<template>
  <div class="container">
    <div class="input_modal">
      <div class="input-item">
        <span>发表人：</span>
         <el-input v-model="trueName" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <span>发布人手机：</span>
         <el-input v-model="userName" placeholder="请输入内容" class="proName" @keyup.enter.native="search"></el-input>
      </div>
      <div class="input-item">
        <span>发表时间：</span>
         <el-date-picker
            v-model="dateArr"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
        <el-button icon="el-icon-search" type="primary" size="medium" @click="getList">查询</el-button>
      </div>
    </div>
    <div class="table_con">
      <el-table v-loading="loading" :data="tableData" :border='true'>
        <el-table-column :formatter="formatter" prop="id" label="发表编号"></el-table-column>
        <el-table-column :formatter="formatter" prop="esShopUserCoreDTO.trueName" label="发表人/所属集团">
          <template slot-scope="scope">
            {{scope.row.esShopUserCoreDTO.trueName?scope.row.esShopUserCoreDTO.trueName:scope.row.esShopUserCoreDTO.userName}}
          </template>
        </el-table-column>
        <el-table-column :formatter="formatter" prop="esShopUserCoreDTO.mobile" label="发送手机号/定制账号"></el-table-column>
        <el-table-column :formatter="formatter" prop="title" label="标题"></el-table-column>
        <el-table-column :formatter="formatter" prop="detail" label="反馈意见"></el-table-column>
        <el-table-column :formatter="formatter" prop="gmtCreated" label="发表时间"></el-table-column>
        <el-table-column prop="" label="操作">
          <template slot-scope="scope">
            <el-button @click="linkTo('viewDetail',scope.row.id)" type="primary" size="mini">查看</el-button>
            <el-button icon="el-icon-delete" type="danger" size="mini" @click="deleteRole(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageIndex" :page-size="pageSize" :page-sizes='[10,20,30,40]' layout="total, sizes, prev, pager, next, jumper" :total="pageCount">
      </el-pagination>
    </div>
    <el-dialog title="添加/编辑品牌" :visible.sync="dialogVisible" width="30%">
      <div class="tag-head">
        <el-form :model="user" :rules="rules" ref="user" label-width="120px" class="">
          <el-form-item label="品牌名" prop="papersName">
            <el-input v-model="user.brandName" placeholder="请输入"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handSave('user')" type="primary">确 定</el-button>
        <el-button style="margin-right:30%" type="primary" @click="dialogVisible = false">返 回</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
let CONSTANT = require("../../constant/constant.js");
let common = require("../../common.js");
export default {
  data() {
    return {
      tableData: [],
      dateArr:[],
      dialogVisible:false,
      pageCount: null,
      pageIndex: 1,
      pageSize: 10,
      loading: true,
      trueName: null,
      userName:null,
      user:{
          id:'',
          brandName:''
      }
    };
  },
  mounted() {
    this.pageIndex = this.$router.currentRoute.query.pageIndex
      ? this.$router.currentRoute.query.pageIndex
      : 1;
    this.getList();
  },
  methods: {
    formatter(row, column, cellValue) {
      return cellValue ? cellValue : "- -";
    },
    linkTo(path,id){
        this.$router.push(path+'?id='+id+'&pageIndex='+this.pageIndex)
    },
    addBtn(){
        this.$router.push('noticeDetail?pageIndex='+this.pageIndex)
    },  
    editBtn(obj){
        this.user = {
            id:obj.id,
            brandName:obj.brandName
        }
        this.dialogVisible = true
    },
    deleteRole:function(id) {
        this.$confirm('确定删除?', '提示', {           
            confirmButtonText: '确定',           
            cancelButtonText: '取消',           
            type: 'warning'         
        }).then(() => {           
            let  url = CONSTANT.URL.LIST.deleteEsAdvice;
            let param = {id:id} ;
            common.requestAjax(url,JSON.stringify(param),null,(res)=>{
                if(res.status == 200){
                    this.$message({
                        type:'success',
                        message:'删除成功!'
                    });
                    this.getList();
                }
                else{
                    this.$message({
                        type:'warning',
                        message:res.msg
                    })
                }
            })      
        }).catch(() => {           
            this.$message({             
                type: 'info',             
                message: '已取消删除'           
            });                   
        });    
    },
    getList: function() {
        let endDate,beginDate;
        if(this.dateArr.length){
            beginDate = this.dateArr[0]
            endDate = this.dateArr[1]
        }
      let url = CONSTANT.URL.LIST.findEsAdviceByPage;
      let data = {
        pageIndex: this.pageIndex,
        pageSize: this.pageSize,
        trueName:this.trueName,
        userName:this.userName,
      };
      this.loading = true;
      common.requestAjax(url, JSON.stringify(data), null, res => {
        this.loading = false;
        let data = res.data;
        this.tableData = data.bussData;
        this.pageCount = data.count;
      });
    },
    search: function(e) {
      if (e.keyCode == 13) {
        this.pageIndex = 1;
        this.getList();
      }
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getList();
    }
  }
};
</script>
